package org.gdufe.users.controller;

import org.gdufe.pojos.dto.InsertBookDto;
import org.gdufe.pojos.dto.InsertUserDto;
import org.gdufe.pojos.dto.PageParams;
import org.gdufe.pojos.dto.UpdateUserDto;
import org.gdufe.pojos.vo.PageResponseResult;
import org.gdufe.pojos.vo.R;
import org.gdufe.users.mapper.UserMapper;
import org.gdufe.users.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    //分页查询用户信息
    @GetMapping("/querry")
    @PreAuthorize("hasAuthority('super')")
    public PageResponseResult querry( PageParams pageParams, @RequestParam(required = false) String username){
        return userService.querry(pageParams,username);
    }

    //根据id查找用户
    @GetMapping("/select")
    @PreAuthorize("hasAuthority('super')")
    public R select(Integer id){
        return userService.select(id);
    }

    //添加用户
    @PostMapping("/insert")
    @PreAuthorize("hasAuthority('super')")
    public R insert(@RequestBody InsertUserDto insertUserDto){
        return userService.insert(insertUserDto);
    }

    //更新用户信息
    @PutMapping("/update")
    @PreAuthorize("hasAuthority('super')")
    public R update(@RequestBody UpdateUserDto updateUserDto){
        return userService.update(updateUserDto);
    }

    //删除用户信息
    @DeleteMapping("/delete")
    @PreAuthorize("hasAuthority('super')")
    public R delete(Integer id){
        return userService.delete(id);
    }
}
